import parse from '@dfeidao/atom-web/dt/parse';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import refresh from '@dfeidao/atom-web/url/refresh';

export default async function a004(fd: IFeidaoAiBrowserComponent) {
	// todo

	const no = get(fd, 'no');
	const a1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="equip_type_no"]');
	const a2 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="equipment_kind_no"]');
	const a3 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="value1"]');
	const a4 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="value2"]');
	const a5 = fd.data.node.querySelector<HTMLInputElement>('[data-id="equip_internal_no"]');
	const a6 = fd.data.node.querySelector<HTMLInputElement>('[data-id="transfer_price"]');
	const a7 = fd.data.node.querySelector<HTMLInputElement>('[data-id="transfer_time"]');
	const a8 = fd.data.node.querySelector<HTMLInputElement>('[data-id="date"]');
	const e_type_no = get(fd, 'equip_type_no') as { equip_type_no: string };
	// console.log('111222', e_type_no);
	const d = get(fd, 'data');
	const d1 = get(fd, 'data1');
	console.log(d);
	console.log(d1);
	const res = await nodejs<{ code: 0 | 1, mes: string }>('device-management-ygh/zj-000010/s006', {
		data: {
			equip_no: no,
			equip_type_name: a1.selectedOptions[0].text,
			equip_type_no: e_type_no.equip_type_no,
			equip_internal_no: a5.value,
			equip_name: a2.selectedOptions[0].text,
			fixed_assets_type: a3.selectedOptions[0].text,
			equipment_state: a4.selectedOptions[0].text,
			transfer_time: a7.value,
			transfer_price: a6.value,
			transfer_date: parse(a8.value)
		},
		hidden_info: d
		// hidden_data: d,
		// design_data: d1
	});
	const res1 = await nodejs<{ code: 0 | 1, mes: string }>('device-management-ygh/zj-000010/s011', {
		data: {
			equip_no: no
		}, design_data: d1
	});
	if (res.code === 1 && res1.code === 1) {
		alert('保存成功');
		refresh();
	} else {
		alert('保存失败');
	}
}
